package cn.edu.zut.score.controller;

import cn.edu.zut.score.core.domain.RestResponse;
import cn.edu.zut.score.core.dto.request.LoginRequest;
import cn.edu.zut.score.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zby
 * @date 2021/06/25
 */
@RestController
@CrossOrigin
public class CommonController {

    @Autowired
    private IUserService iUserService;

    @ApiOperation("用户登录：成功返回token，失败返回信息")
    @PostMapping("/login")
    public RestResponse<String> login(@RequestBody LoginRequest loginRequest) {
        return iUserService.login(loginRequest);
    }

    @ApiOperation("获取当前用户信息")
    @GetMapping("/info")
    public RestResponse<Map<String, String>> info() {
        return iUserService.info();
    }

    @ApiOperation("获取当前用户密码是否为初始密码")
    @GetMapping("/p")
    public RestResponse<Boolean> isPasswordValid() {
        return iUserService.isPasswordValid();
    }

    @ApiOperation("用户手动退出登录")
    @RequestMapping("/logout")
    public RestResponse<String> logout() {
        return iUserService.logout();
    }

}
